package gold.digger;

/**
 * Created by fanzhenyu02 on 2020/3/1.
 */
public class LC335 {

    /*
     * @param 此题目参考了别人代码
     * 这是因为问题情况较为复杂
     * @return:
     */
    public boolean isSelfCrossing(int[] x) {
        for (int i = 3; i < x.length; ++i) {
            if (x[i] >= x[i - 2] && x[i - 3] >= x[i - 1]) {
                return true;
            }
            if (i >= 4 && x[i - 1] == x[i - 3] && x[i] >= x[i - 2] - x[i - 4]) {
                return true;
            }
            if (i >= 5 && x[i - 2] >= x[i - 4] && x[i - 3] >= x[i - 1] &&
                    x[i - 1] >= x[i - 3] - x[i - 5] && x[i] >= x[i - 2] - x[i - 4]) {
                return true;
            }
        }
        return false;
    }

    public static void main(String[] args) {
        LC335 an = new LC335();
        int[] arr = {1, 1, 2, 2, 1, 1};

        System.out.println(an.isSelfCrossing(arr));
    }

}
